package com.pro.controller;

import com.pro.pojo.JsGoodsCategroy;
import com.pro.pojo.JsonData;
import com.pro.service.JsGoodsCategroyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author cyj
 * @date 2022.1.11$ 9.23$
 * @content :
 */
@RestController
@RequestMapping("/JsGoodsTree")
public class JsGoodsCategroyController {
    @Autowired
    private JsGoodsCategroyService service;

    /*获取树节点信息*/
    @RequestMapping("/getTree")
    public JsonData getTree(){
        List<JsGoodsCategroy> list=service.getTree();
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务器错误");
    }

    /*删除一个节点  22.1.11   11.46  CYJ*/
    @RequestMapping("/delTreeNode")
    public JsonData delTreeNode(Integer categroyId){
        Boolean flag=service.delGoodsCategroy(categroyId);
        return flag!=false?JsonData.buildSuccess(flag):JsonData.buildError("服务器错误");
    }

    /*编辑一个节点  22.1.11   13.34  CYJ*/
    @RequestMapping("/updateGoodsCategroy")
    public JsonData updateGoodsCategroy(JsGoodsCategroy JsGoodsCategroy){
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        Date dateTime = null;
        try {
            dateTime = df.parse(df.format(new Date()));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        JsGoodsCategroy.setUpdateDate(dateTime);
        Boolean flag=service.updateGoodsCategroy(JsGoodsCategroy);
        return flag!=false?JsonData.buildSuccess(flag):JsonData.buildError("服务器错误");
    }

    /*新增一个节点  22.1.11   15.11  CYJ*/
    @RequestMapping("/addGoodsCategroy")
    public JsonData addGoodsCategroy(JsGoodsCategroy JsGoodsCategroy){
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        Date dateTime = null;
        try {
            dateTime = df.parse(df.format(new Date()));
        } catch (ParseException e) {
            System.out.println("");
            e.printStackTrace();
        }
        JsGoodsCategroy.setCreateDate(dateTime);
        Boolean flag=service.addGoodsCategroy(JsGoodsCategroy);
        return flag!=false?JsonData.buildSuccess(flag):JsonData.buildError("服务器错误");
    }
}
